import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const createRouter = () => new VueRouter({
  mode: 'hash',
  scrollBehavior: () => ({y: 0}),
  routes: [
    {
      path: '/',
      name: 'Home',
      redirect: {name: 'Demo'},
      meta: {title: '首页'}
    },
    {
      path: '/demo',
      name: 'Demo',
      component: () => import('@/views/home'),
      meta: {title: '播放器'}
    },
    {
      path: '/screen',
      name: 'Screen',
      component: () => import('@/views/home/largeVisualScreen.vue'),
      meta: {title: '播放器'}
    }
  ]
})

const router = createRouter()

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err)
}

/**
 * 重置路由*退出登录 删除动态添加的路由
 *
 */
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
